<template>
  <el-form :model="form" status-icon :rules="rules" ref="form" label-width="100px" class="demo-ruleForm">
    <el-form-item label="用户名" prop="username">
      <el-input type="text" v-model="form.username" ></el-input>
    </el-form-item>
    <el-form-item label="密码" prop="pwd">
      <el-input type="password" v-model="form.pwd" ></el-input>
    </el-form-item>

    <el-form-item>
      <el-button type="primary" @click="submitForm()">提交</el-button>
      <el-button @click="resetForm('ruleForm')">重置</el-button>
    </el-form-item>
  </el-form>
</template>
<script>
export default {
  data() {

    return {
      form: {

      },
      rules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
        ],
        pwd: [
          { required: true, message: '请输入密码', trigger: 'blur' },
        ],

      }
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.axios.get("http://localhost:83/user/login",{params:this.form}).then(res=>{
            if(res.data.flag){
              window.localStorage.setItem("token",res.data.msgData);
              this.$router.push("/list");
              this.$message.success("登录成功");
            }else{
              this.$message.error(res.data.msgInfo);
            }
          })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }
}
</script>